package com.songlanyun.modules.logisticscompany.controller.admin;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.common.validator.group.AddGroup;
import com.songlanyun.common.validator.group.UpdateGroup;
import com.songlanyun.modules.user.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.logisticscompany.entity.SystemLogisticsCompanyEntity;
import com.songlanyun.modules.logisticscompany.service.SystemLogisticsCompanyService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;


/**
 * 平台发布的可适用的物流公司表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-12 11:05:31
 */
@RestController
@RequestMapping("admin/logistics/company")
public class SystemLogisticsCompanyAdminController extends AbstractController {
    @Autowired
    private SystemLogisticsCompanyService systemLogisticsCompanyService;

    /**
     * 列表
     */
    @GetMapping("/list")
//    @RequiresPermissions("logistics:systemlogisticscompany:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = systemLogisticsCompanyService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @GetMapping("/select")
//    @RequiresPermissions("logistics:systemlogisticscompany:list")
    public R select() {
        List<SystemLogisticsCompanyEntity> list = systemLogisticsCompanyService.list();

        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
//    @RequiresPermissions("logistics:systemlogisticscompany:info")
    public R info(@PathVariable("id") Integer id) {
        SystemLogisticsCompanyEntity systemlogisticscompany = systemLogisticsCompanyService.getById(id);

        return R.ok().put("data", systemlogisticscompany);
    }

    /**
     * 保存
     */
    @SysLog("保存物流公司")
    @PostMapping("/save")
//    @RequiresPermissions("logistics:systemlogisticscompany:save")
    public R save(@RequestBody SystemLogisticsCompanyEntity systemlogisticscompany) {
        verifyAdmin();
        ValidatorUtils.validateEntity(systemlogisticscompany, AddGroup.class);
        systemLogisticsCompanyService.save(systemlogisticscompany);

        return R.ok();
    }

    /**
     * 修改
     */
    @SysLog("修改物流公司")
    @PutMapping("/update")
//    @RequiresPermissions("logistics:systemlogisticscompany:update")
    public R update(@RequestBody SystemLogisticsCompanyEntity systemlogisticscompany) {
        verifyAdmin();
        ValidatorUtils.validateEntity(systemlogisticscompany, UpdateGroup.class);
        systemLogisticsCompanyService.updateById(systemlogisticscompany);

        return R.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除物流公司")
    @DeleteMapping("/delete/{id}")
//    @RequiresPermissions("logistics:systemlogisticscompany:delete")
    public R delete(@PathVariable Integer id) {
        verifyAdmin();
        systemLogisticsCompanyService.removeById(id);

        return R.ok();
    }

}
